<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class loadClassInformation extends CI_Controller {
    public function loadClassInformationfromFile()
    {
    	$this->load->model('user_model',null,true);           
    	$query = $this->db->query('SELECT * FROM class');
		$fileArray=array();
		$fileArray=$query->result_array();	
		$fileChon='';
		$data = array();
		$queryTemp = $this->db->query('SELECT * FROM temp where type = "class"');
		$tempArray=array();
		$tempArray=$queryTemp->result_array();
		$fileChon=$tempArray[0]['name'];
		$fileCurrent = $fileChon;
		$arrayFileChon = explode('-',$fileChon);
		$fileChon = $arrayFileChon[0].$arrayFileChon[1].$arrayFileChon[2].$arrayFileChon[3].$arrayFileChon[4].$arrayFileChon[5].'.xls';
		if ($_SERVER['REQUEST_METHOD'] == 'POST'){
			$fileChonMoi = $_POST['fileExcelClass'];
			$arrayFileChon = explode('-',$fileChonMoi);
			$fileChon = $arrayFileChon[0].$arrayFileChon[1].$arrayFileChon[2].$arrayFileChon[3].$arrayFileChon[4].$arrayFileChon[5].'.xls';
			$array =array(
				'name'=> $fileChonMoi,
			);
			$this->user_model->updateCurrentTravel($array);
			//var_dump($arrayTravel);
			//---------------lay data from excel --------------------------
			$queryTemp = $this->db->query('SELECT * FROM temp where type = "travel"');
			$tempArray=array();
			$tempArray=$queryTemp->result_array();
			$fileCurrent=$tempArray[0]['name'];
		}
		
		$feedId = 9;
		//var_dump($arrayTravel);
		//---------------lay data from excel --------------------------
		$filename="./feed/class/".$fileChon; // file du lieu demmo chi gom 2 cot hoten va diem
		require_once 'excel_reader2.php'; // nhung thu vien xu ly ma nguon mo 
		$data = new Spreadsheet_Excel_Reader($filename,true,"UTF-8"); // khoi tao doi tuong doc file excel 
		$rowsnum = $data->rowcount($sheet_index=0); // lay so hang cua sheet
		$colsnum =  $data->colcount($sheet_index=0); // lay so cot cua sheet
		$arrayclass = array();
		for ($i=2;$i<=$rowsnum;$i++){ // doc tu hang so 2 vi hang 1 la tieu de roi!
			$feedId++;
			$arrayclass[] = array($feedId,$data->val($i,1),$data->val($i,2),$data->val($i,3),$feedId,$data->val($i,4),$data->val($i,5),$data->val($i,6),$feedId,$data->val($i,7),$data->val($i,8),$data->val($i,9)); 
			//echo "<br>".$data->val($i,1)." , ".$data->val($i,2). " , " .$data->val($i,3) ;// xuat cot so 1 va cot so 2 tren cung 1 hang	
		} 	
		

		$arrayFile = array();
    	$data = array();
    	$data['fileCurrent']=$fileCurrent; 
    	$data['controller']='feed/';
    	$data['name_view']='loadInformation';
    	$data['arrayClass']=$arrayclass;
    	$data['fileArray']=$fileArray;
        $this->load->view('template',$data);
    }
}